package com.moxiao.yfjh.module.blind.controller.admin.constellationtest;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.moxiao.yfjh.framework.common.pojo.PageResult;
import com.moxiao.yfjh.framework.common.pojo.CommonResult;
import static com.moxiao.yfjh.framework.common.pojo.CommonResult.success;

import com.moxiao.yfjh.framework.excel.core.util.ExcelUtils;

import com.moxiao.yfjh.framework.operatelog.core.annotations.OperateLog;
import static com.moxiao.yfjh.framework.operatelog.core.enums.OperateTypeEnum.*;

import com.moxiao.yfjh.module.blind.controller.admin.constellationtest.vo.*;
import com.moxiao.yfjh.module.blind.dal.dataobject.constellationtest.ConstellationTestDO;
import com.moxiao.yfjh.module.blind.convert.constellationtest.ConstellationTestConvert;
import com.moxiao.yfjh.module.blind.service.constellationtest.ConstellationTestService;

@Tag(name = "管理后台 - 相亲会员星座测试")
@RestController
@RequestMapping("/blind/constellation-test")
@Validated
public class ConstellationTestController {

    @Resource
    private ConstellationTestService constellationTestService;

    @PostMapping("/create")
    @Operation(summary = "创建相亲会员星座测试")
    @PreAuthorize("@ss.hasPermission('blind:constellation-test:create')")
    public CommonResult<Long> createConstellationTest(@Valid @RequestBody ConstellationTestCreateReqVO createReqVO) {
        return success(constellationTestService.createConstellationTest(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新相亲会员星座测试")
    @PreAuthorize("@ss.hasPermission('blind:constellation-test:update')")
    public CommonResult<Boolean> updateConstellationTest(@Valid @RequestBody ConstellationTestUpdateReqVO updateReqVO) {
        constellationTestService.updateConstellationTest(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除相亲会员星座测试")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('blind:constellation-test:delete')")
    public CommonResult<Boolean> deleteConstellationTest(@RequestParam("id") Long id) {
        constellationTestService.deleteConstellationTest(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得相亲会员星座测试")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('blind:constellation-test:query')")
    public CommonResult<ConstellationTestRespVO> getConstellationTest(@RequestParam("id") Long id) {
        ConstellationTestDO constellationTest = constellationTestService.getConstellationTest(id);
        return success(ConstellationTestConvert.INSTANCE.convert(constellationTest));
    }

    @GetMapping("/list")
    @Operation(summary = "获得相亲会员星座测试列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('blind:constellation-test:query')")
    public CommonResult<List<ConstellationTestRespVO>> getConstellationTestList(@RequestParam("ids") Collection<Long> ids) {
        List<ConstellationTestDO> list = constellationTestService.getConstellationTestList(ids);
        return success(ConstellationTestConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得相亲会员星座测试分页")
    @PreAuthorize("@ss.hasPermission('blind:constellation-test:query')")
    public CommonResult<PageResult<ConstellationTestRespVO>> getConstellationTestPage(@Valid ConstellationTestPageReqVO pageVO) {
        PageResult<ConstellationTestDO> pageResult = constellationTestService.getConstellationTestPage(pageVO);
        return success(ConstellationTestConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出相亲会员星座测试 Excel")
    @PreAuthorize("@ss.hasPermission('blind:constellation-test:export')")
    @OperateLog(type = EXPORT)
    public void exportConstellationTestExcel(@Valid ConstellationTestExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<ConstellationTestDO> list = constellationTestService.getConstellationTestList(exportReqVO);
        // 导出 Excel
        List<ConstellationTestExcelVO> datas = ConstellationTestConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "相亲会员星座测试.xls", "数据", ConstellationTestExcelVO.class, datas);
    }

}
